package com.huawei.struts.dao;

import java.util.Date;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.st.model.LjwAlbumImgT;

/**
 * A data access object (DAO) providing persistence and search support for
 * LjwAlbumImgT entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see com.st.model.LjwAlbumImgT
 * @author MyEclipse Persistence Tools
 */

public class LjwAlbumImgTDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory.getLog(LjwAlbumImgTDAO.class);
	// property constants
	public static final String ALBUM_IMG_NAME = "albumImgName";
	public static final String ALBUM_IMG_URL = "albumImgUrl";
	public static final String ALBUM_ID = "albumId";
	public static final String VISIT_COUNT = "visitCount";
	public static final String USER_ID = "userId";

	protected void initDao() {
		// do nothing
	}

	public void save(LjwAlbumImgT transientInstance) {
		log.debug("saving LjwAlbumImgT instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(LjwAlbumImgT persistentInstance) {
		log.debug("deleting LjwAlbumImgT instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public LjwAlbumImgT findById(java.lang.Integer id) {
		log.debug("getting LjwAlbumImgT instance with id: " + id);
		try {
			LjwAlbumImgT instance = (LjwAlbumImgT) getHibernateTemplate().get(
					"com.st.model.LjwAlbumImgT", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(LjwAlbumImgT instance) {
		log.debug("finding LjwAlbumImgT instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding LjwAlbumImgT instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from LjwAlbumImgT as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByAlbumImgName(Object albumImgName) {
		return findByProperty(ALBUM_IMG_NAME, albumImgName);
	}

	public List findByAlbumImgUrl(Object albumImgUrl) {
		return findByProperty(ALBUM_IMG_URL, albumImgUrl);
	}

	public List findByAlbumId(Object albumId) {
		return findByProperty(ALBUM_ID, albumId);
	}

	public List findByVisitCount(Object visitCount) {
		return findByProperty(VISIT_COUNT, visitCount);
	}

	public List findByUserId(Object userId) {
		return findByProperty(USER_ID, userId);
	}

	public List findAll() {
		log.debug("finding all LjwAlbumImgT instances");
		try {
			String queryString = "from LjwAlbumImgT";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public LjwAlbumImgT merge(LjwAlbumImgT detachedInstance) {
		log.debug("merging LjwAlbumImgT instance");
		try {
			LjwAlbumImgT result = (LjwAlbumImgT) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(LjwAlbumImgT instance) {
		log.debug("attaching dirty LjwAlbumImgT instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(LjwAlbumImgT instance) {
		log.debug("attaching clean LjwAlbumImgT instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static LjwAlbumImgTDAO getFromApplicationContext(
			ApplicationContext ctx) {
		return (LjwAlbumImgTDAO) ctx.getBean("LjwAlbumImgTDAO");
	}
}